package com.colin.aiyi.dao.ImpxUtils;

import com.colin.aiyi.entity.response.LoginResponse;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.presenter.Interface.Callback;

import org.xutils.http.RequestParams;

import static com.colin.aiyi.app.Constant.login;

/**
 * Created by hl on 2017/6/9.
 */

public class ImpLogin  extends AbsServicexUtils{

    private long firstTime;

    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        LoginResponse loginResponse=gson.fromJson(result,LoginResponse.class);
        if (callback==null)
        {
            sendMsgToView(loginResponse);
        }else {
            callback.onSuccess(loginResponse);
        }
    }

    @Override
    public <T, V> void getObject(Callback<T> t, V v) {
        super.getObject(t, v);
        getObject(v);
    }

    @Override
    public <V> void getObject(V v) {
        super.getObject(v);
        if (System.currentTimeMillis()-firstTime>1500){
            if (v instanceof User)
            {
                User user= (User) v;
                RequestParams params=new RequestParams(login);
//        params.addBodyParameter("clientId",Constant.CLIENT_ID);
//        params.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
                params.addBodyParameter("tel",user.getTelNo());
                params.addBodyParameter("password",user.getPassword());
                sendToServer(params);
            }
            firstTime=System.currentTimeMillis();
        }else{
        }

    }
}
